Imports System.Xml
Imports System.Net
Imports System.IO
Imports System.Deployment

Imports System.Data.OleDb
Public Class Nabaztag_API


    Public apiurl As String = Me.dbconnect.ToString


    ' *****************************************************
    ' *   API CONNECTION CLASS                            *
    ' *                                                   *
    ' *****************************************************

    Public Function sendapi(ByVal tts As String, ByVal serial As String, ByVal token As String, ByVal Voice As String) As String


        ' *****************************************************
        ' *   Determine What voice is used                    *
        ' *                                                   *
        ' *****************************************************
        Dim voicemod As String


        If Voice = "Heather" Then
            voicemod = Voice.ToLower & "22k"
        End If
        If Voice = "Ryan" Then
            voicemod = Voice.ToLower & "22k"

        Else : voicemod = Voice.ToLower & "22s"
        End If

        Dim uri As String
        Dim output As String = ""

        tts = tts.Replace(" ", "+")
        uri = apiurl & "key=431561751&sn=" & serial & "&token=" & token & "&tts=" & tts & "&voice=" & voicemod


        ' *****************************************************
        ' *   SEND AS AN XML READER                           *
        ' *                                                   *
        ' *****************************************************



        Using reader As XmlReader = XmlReader.Create(uri)
            While reader.Read()
                If reader.IsStartElement() Then
                    If reader.IsEmptyElement Then
                        MsgBox("<{0}/>", reader.Name)
                        If output = "" Then
                            Return output
                        End If
                        Return uri
                    Else
                        reader.Read() ' Read the start tag.
                        If reader.IsStartElement() Then ' Handle nested elements.


                            output = reader.ReadString()
                            reader.ReadEndElement()
                            output = reader.ReadString()
                            Return uri + "[" + output

                        End If

                    End If


                End If

            End While

            reader.Close()

        End Using

    End Function




    Public Function actionapi(ByVal serial As String, ByVal token As String, ByVal action As String) As String




        Dim uri As String
        Dim output As String = ""


        uri = apiurl & "key=431561751&sn=" & serial & "&token=" & token & "&action=" & action



        
        Return uri 

    End Function









    Public Function radioapi(ByVal Serial As String, ByVal Token As String, ByVal URL As String) As String

        Dim sUri As String
        sUri = apiurl & "sn=" & Serial & "&token=" & Token & "&urlList=" & URL

        Dim myUri As System.Uri = New System.Uri(sUri)


        Using reader As XmlReader = XmlReader.Create(sUri)

            While reader.Read()
                If reader.IsStartElement() Then
                    If reader.IsEmptyElement Then
                        MsgBox("<{0}/>", reader.Name)
                        Return sUri
                    Else
                        reader.Read() ' Read the start tag.
                        If reader.IsStartElement() Then ' Handle nested elements.

                            Dim output As String

                            output = reader.ReadString()

                            reader.ReadEndElement()
                            output = reader.ReadString()
                            Return sUri + "[" + output
                        End If

                    End If
                End If
            End While
        End Using



    End Function

    Public Function dbconnect() As String
        Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Rabbit.mdb;Persist Security Info=False"
        Dim cmd As String = "Select content from Settings"
        Dim adapter As New OleDbDataAdapter(cmd, conn)
        Dim topics As New DataSet
        adapter.Fill(topics)
        
        Dim temp As New XmlDocument



        temp.LoadXml(topics.GetXml)
        Return temp.InnerText.ToString
        topics.Dispose()

        


    End Function
End Class
